const setToken=(token:string,expiration=3600)=>{
    const expires=new Date();
    expires.setTime(expires.getTime()+expiration*1000);
    localStorage.setItem('token',token);
    localStorage.setItem('token_expires',expires.toISOString());

}
const getToken=()=>{
    const token=localStorage.getItem('token');
    const expires=localStorage.getItem('token_expires');
    if(!token|| !expires) return null;
    const expiresDate=new Date(expires);
    if(expiresDate<=new Date()){
        clearToken();
        return null;
    }
    return token;
}
const clearToken=()=>{
    localStorage.removeItem('token');
    localStorage.removeItem('token_expires');
}
export {setToken,getToken,clearToken};